package com.boruishangge.home.adapter;


import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.boruishangge.home.bean.HomeTabBean;
import com.boruishangge.home.fragment.HomeListFragment;

import java.util.ArrayList;
import java.util.List;

public class ChannelPagerAdapter extends FragmentStatePagerAdapter {

    private List<HomeListFragment> mFragments;
    private List<HomeTabBean> mChannels;

    public ChannelPagerAdapter(List<HomeListFragment> fragmentList, List<HomeTabBean> channelList, FragmentManager fm) {
        super(fm);
        if (fragmentList==null||mFragments==null){
            mFragments=fragmentList;
        }else {
            mFragments=new ArrayList<>();
        }
        if (channelList==null||mChannels==null){
            mChannels=channelList;
        }else {
            mChannels=new ArrayList<>();
        }
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mChannels.get(position).getName();
    }

    @Override
    public int getItemPosition(Object object) {
        //        if (mChildCount > 0) {
        //            mChildCount--;
        return POSITION_NONE;
        //        }
        //        return super.getItemPosition(object);
    }
}
